﻿<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
dim act:act=lcase(sdcms.fpost("act",0))
dim formvalue:formvalue=sdcms.fpost(act,0)

function errcode(byval t0)
	errcode="{""error"":"""&t0&"""}"
end function

function succcode()
	succcode="{""ok"":""""}"
end function

sub checkusername()
	if sdcms.strlen(formvalue)=0 then
		sdcms.echo errcode("&#29992;&#25143;&#21517;&#19981;&#33021;&#20026;&#31354;")
		exit sub
	end if
	if not(sdcms.checkstr(formvalue,"username")) then
		sdcms.echo errcode("&#30001;&#53;&#45;&#50;&#48;&#20301;&#23383;&#27597;&#12289;&#25968;&#23383;&#12289;&#19979;&#21010;&#32447;&#32452;&#25104;")
		exit sub
	end if
	dim baduser:baduser=sdcms.getsys("baduser")
	if sdcms.strlen(baduser)>0 then
		baduser="|"&baduser&"|"
		if instr(baduser,"|"&formvalue&"|")>0 then
			sdcms.echo errcode("&#31995;&#32479;&#31105;&#27490;&#27880;&#20876;&#27492;&#29992;&#25143;&#21517;&#65292;&#35831;&#25442;&#20010;&#35797;&#35797;")
			exit sub
		end if
	end if
	if sdcms.db.dbcount("sd_user","username='"&formvalue&"'")>0 then
		sdcms.echo errcode("&#29992;&#25143;&#21517;&#24050;&#23384;&#22312;&#65292;&#35831;&#25442;&#20010;&#35797;&#35797;")
		exit sub
	end if
	sdcms.echo succcode
end sub


sub checkemail()
	if sdcms.strlen(formvalue)=0 then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#19981;&#33021;&#20026;&#31354;")
		exit sub
	end if
	if not(sdcms.checkstr(formvalue,"email")) then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#26684;&#24335;&#19981;&#27491;&#30830;")
		exit sub
	end if
	if sdcms.db.dbcount("sd_user","email='"&formvalue&"'")>0 then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#24050;&#23384;&#22312;&#65292;&#35831;&#25442;&#20010;&#35797;&#35797;")
		exit sub
	end if
	sdcms.echo succcode
end sub

sub checkemailpass()
	if sdcms.strlen(formvalue)=0 then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#19981;&#33021;&#20026;&#31354;")
		exit sub
	end if
	if not(sdcms.checkstr(formvalue,"email")) then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#26684;&#24335;&#19981;&#27491;&#30830;")
		exit sub
	end if
	if sdcms.db.dbcount("sd_user","email='"&formvalue&"'")<=0 then
		sdcms.echo errcode("&#24744;&#36755;&#20837;&#30340;&#30005;&#23376;&#37038;&#31665;&#19981;&#23384;&#22312;")
		exit sub
	end if
	sdcms.echo succcode
end sub

sub checkemailedit()
	if sdcms.strlen(formvalue)=0 then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#19981;&#33021;&#20026;&#31354;")
		exit sub
	end if
	if not(sdcms.checkstr(formvalue,"email")) then
		sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#26684;&#24335;&#19981;&#27491;&#30830;")
		exit sub
	end if
	dim userdata:userdata=sdcms.userinfo
	if formvalue<>userdata(3) then
		if sdcms.db.dbcount("sd_user","email='"&formvalue&"'")>0 then
			sdcms.echo errcode("&#30005;&#23376;&#37038;&#31665;&#24050;&#23384;&#22312;&#65292;&#35831;&#25442;&#20010;&#35797;&#35797;")
			exit sub
		end if
	end if
	sdcms.echo succcode
end sub

sub checkimgcode()
	if sdcms.strlen(formvalue)=0 then
		sdcms.echo errcode("&#39564;&#35777;&#30721;&#19981;&#33021;&#20026;&#31354;")
		exit sub
	end if
	if sdcms.loadsession("imgcode")<>formvalue then
		sdcms.echo errcode("&#39564;&#35777;&#30721;&#38169;&#35823;")
		exit sub
	end if
	sdcms.echo succcode
end sub

sub checkoldpass()
	dim userdata:userdata=sdcms.userinfo
	if md5(formvalue)<>userdata(2) then
		sdcms.echo errcode("&#21407;&#23494;&#30721;&#19981;&#27491;&#30830;")
		exit sub
	end if
	sdcms.echo succcode
end sub

sub checkfavorite()
	if not(sdcms.is_login) then
		sdcms.echo ("0&#24744;&#38656;&#35201;&#30331;&#24405;&#21518;&#25165;&#33021;&#25910;&#34255;")
		exit sub
	end if
	dim t0:t0=sdcms.getint(sdcms.fpost("t0",1),0)
	if t0=0 then
		sdcms.echo ("1&#21442;&#25968;&#38169;&#35823;")
		exit sub
	end if
	if sdcms.db.dbcount("sd_content","id="&t0&" and islock=1")=0 then
		sdcms.echo ("1&#21442;&#25968;&#38169;&#35823;")
		exit sub
	end if
	dim userdata,userid
	userdata=sdcms.userinfo
	userid=userdata(0)
	if sdcms.db.dbcount("sd_user_favorite","contentid="&t0&" and userid="&userid&"")>0 then
		sdcms.echo ("1&#24050;&#25910;&#34255;")
		exit sub
	else
		sdcms.db.insert "sd_user_favorite",array(array("userid",userid,0,0),array("contentid",t0,0,0),array("createdate",sqltime,0,0))
		sdcms.echo ("2&#25910;&#34255;&#25104;&#21151;")
	end if
end sub

select case act
	case "username":checkusername
	case "email":checkemail
	case "emailpass":checkemailpass
	case "emailedit":checkemailedit
	case "imgcode":checkimgcode
	case "oldpass":checkoldpass
	case "favorite":checkfavorite
	case else
		sdcms.echo "{""error"":"""&act&"""}"
end select

sdcms.db.dbclose
%>